﻿using ERP_RORZE_DLL.Product.Base;
using System;using ERP_RORZE_SYSTEM;
using System.Collections.Generic;
using System.Data;
using ERP_RORZE_SYSTEM;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP_RORZE_DLL.Product.database;
using System.Data.SqlClient;

namespace ERP_RORZE_DLL.Product.DAO
{
    public class ClsWTSDAO : ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();
        public DataTable GetAllMachineWTSDetail()
        {
            string sql = clsConstantsFuction.ClsFuctionMachineWTS.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public DataTable GetMachineWTSByID(ClsMachineWTSTable b)
        {
            string sql = clsConstantsFuction.ClsFuctionMachineWTS.GetAllByID;
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ID, SqlDbType.Int, b.ID)
                    
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public DataTable GetAll(int range)
        {

            var parameters = new SqlParameter[]
                    {
						CreateParameter("@Range", SqlDbType.Int, range)
                    };
            //return ExcuteProcedure(ToolConstants.StoreProcedure.Broken.GetAllWithDateRange, parameters);

            string sql = clsConstantsFuction.ClsFuctionMachineWTS.GetAllWithRange;

            return Execute.DoStoreGetByID(sql, parameters, true);


        }
        public DataTable GetAllMachine()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.GetAllMachineWTS;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllLMachine()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.GetAllLMachineWTS;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllStaff()
        {
            string sql = clsConstantsFuction.ClsFuctionStaff.GetAllWTSMachine;
            return Execute.DoStoreProcedure(sql, true);
        }
        public DataTable GetStaffByID(string iD)
        {
            string sql = clsConstantsFuction.ClsFuctionStaff.GetAllById;
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@StaffID", SqlDbType.NVarChar, iD)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllMONo()
        {
            string sql = clsConstantsFuction.ClsFuctionMO.GetAllMOWTS;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllLWTSMONo()
        {
            string sql = clsConstantsFuction.ClsFuctionMO.GetAllLMOWTS;
            return Execute.DoStoreProcedure(sql, true);
        }
        public DataTable GetAllOptionID(string MONo)
        {
            string sql = clsConstantsFuction.ClsFuctionOption.WTSGetAllOptionID;
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo)
                };
            return Execute.DoStoreGetByID(sql,parameter, true);
        }

        public DataTable GetAllOptionIDFilterStg(string MONo)
        {
            string sql = clsConstantsFuction.ClsFuctionOption.WTSGetAllOptionIDFilterStg;
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo)
                };
            return Execute.DoStoreGetByID(sql,parameter, true);
        }

        public DataTable GetAllLOptionID(string MONo)
        {
            string sql = clsConstantsFuction.ClsFuctionOption.LWTSGetAllOptionID;
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllInputTime(string MachineID, int day, int month, int year, string Shift)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MachineID", SqlDbType.NVarChar, MachineID),
                    CreateParameter("@day", SqlDbType.Int, day),
                    CreateParameter("@month", SqlDbType.Int, month),
                    CreateParameter("@year", SqlDbType.Int, year),
                    CreateParameter("@Shift", SqlDbType.NVarChar, Shift)
                    
                };
            return Execute.DoStoreGetByID("sp_242_MachineWTS_TimeInput",parameter, true);
        }

        public DataTable GetAllOptionIDByMONo( string MONo, string OptionID)
        {
            string sql = clsConstantsFuction.ClsFuctionOptionData.GetAllOpt;
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, MONo),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.OptionID, SqlDbType.NVarChar, OptionID)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllVMachineOPTStatusByMONo(string MONo, string OptionID)
        {
            string sql = clsConstantsFuction.ClsFuctionOptionData.intInputed;
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, MONo),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.OptionID, SqlDbType.NVarChar, OptionID)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllVMONGByMONo(string MONo)
        {
            string sql = clsConstantsFuction.ClsFuctionOptionData.MachineNG;
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, MONo)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllMOByMONo(string MONo)
        {
            string sql = clsConstantsFuction.ClsFuctionOptionData.intMoQty;
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, MONo)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllVWTSCheckByMONo(string MONo, string OptionID)
        {
            string sql = clsConstantsFuction.ClsFuctionOptionData.PreOptionOK;
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, MONo),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.OptionID, SqlDbType.NVarChar, OptionID)
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public DataTable GetAllWorkMWTS()
        {
            string sql = clsConstantsFuction.ClsFuctionWork.GetAllMWTS;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllWorkLWTS()
        {
            string sql = clsConstantsFuction.ClsFuctionWork.GetAllLWTS;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Machine WTS
        public void InsertMachineWTS(ClsMachineWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Shift, SqlDbType.NVarChar, b.Shift),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.WorkID, SqlDbType.NVarChar, b.WorkID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Time, SqlDbType.Float, b.Time),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.OKQty, SqlDbType.Int, b.OKQty),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.NGQty, SqlDbType.Int, b.NGQty),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Note1, SqlDbType.NVarChar, b.Note1),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Note2, SqlDbType.NVarChar, b.Note2)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionMachineWTS.Insert, parameter, true);
        }
        public void UpdateMachineWTS(ClsMachineWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Shift, SqlDbType.NVarChar, b.Shift),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.WorkID, SqlDbType.NVarChar, b.WorkID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Time, SqlDbType.Float, b.Time),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.OKQty, SqlDbType.Int, b.OKQty),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.NGQty, SqlDbType.Int, b.NGQty),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Note1, SqlDbType.NVarChar, b.Note1),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Note2, SqlDbType.NVarChar, b.Note2)
                    
                };
            Execute.DoUpdate(clsConstantsFuction.ClsFuctionMachineWTS.Update, parameter, true);
        }

        public int UpdateMachineWTS2(ClsMachineWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Shift, SqlDbType.NVarChar, b.Shift),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.WorkID, SqlDbType.NVarChar, b.WorkID),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Time, SqlDbType.Float, b.Time),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.OKQty, SqlDbType.Int, b.OKQty),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.NGQty, SqlDbType.Int, b.NGQty),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Note1, SqlDbType.NVarChar, b.Note1),
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.Note2, SqlDbType.NVarChar, b.Note2)
                    
                };
           return Execute.DoUpdate2(clsConstantsFuction.ClsFuctionMachineWTS.Update, parameter, true);
        }

        public void DeleteMachineWTS(ClsMachineWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineWTSSP.ID, SqlDbType.Int, b.ID)
                    
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionMachineWTS.Delete, parameter, true);
        }
        public void UpdateMOOption(ClsMOOptionTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.Finishdate, SqlDbType.DateTime, b.Finishdate),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.FinishMachine, SqlDbType.NVarChar, b.FinishMachine),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.Shift, SqlDbType.NVarChar, b.Shift),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.OptionID, SqlDbType.NVarChar, b.OptionID)
                    
                };
            Execute.DoUpdate(clsConstantsFuction.ClsFuctionMachineWTS.UpdateMOOption, parameter, true);
        }

        //Labor WTS
        public DataTable GetAllLaborWTS()
        {
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllLaborWTSTest()
        {
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.Test;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllLaborWTSStaff(string StaffID, int day, int month, int year)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@StaffID", SqlDbType.NVarChar, StaffID),
                    CreateParameter("@day", SqlDbType.Int, day),
                    CreateParameter("@Month", SqlDbType.Int, month),
                    CreateParameter("@Year", SqlDbType.Int, year)
                    
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetCheckStaff;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public DataTable GetAllLaborWTOverTimeStaff(string StaffID, int day, int month, int year)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@StaffID", SqlDbType.NVarChar, StaffID),
                    CreateParameter("@day", SqlDbType.Int, day),
                    CreateParameter("@Month", SqlDbType.Int, month),
                    CreateParameter("@Year", SqlDbType.Int, year)
                    
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetOverTimeStaff;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public void InsertLaborWTS(ClsLaborWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Shift, SqlDbType.NVarChar, b.Shift),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.WorkID, SqlDbType.NVarChar, b.WorkID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.time, SqlDbType.Float, b.Time),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.OKQty, SqlDbType.Int, b.OKQty),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.NGQty, SqlDbType.Int, b.NGQty),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Clamptime, SqlDbType.Float, b.Clamptime),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Note1, SqlDbType.NVarChar, b.Note1),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Note2, SqlDbType.NVarChar, b.Note2)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionLaborWTS.Insert, parameter, true);
        }
        public void UpdateLaborWTS(ClsLaborWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Shift, SqlDbType.NVarChar, b.Shift),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.WorkID, SqlDbType.NVarChar, b.WorkID),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.time, SqlDbType.Float, b.Time),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.OKQty, SqlDbType.Int, b.OKQty),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.NGQty, SqlDbType.Int, b.NGQty),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Clamptime, SqlDbType.Float, b.Clamptime),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Note1, SqlDbType.NVarChar, b.Note1),
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.Note2, SqlDbType.NVarChar, b.Note2)
                    
                };
            Execute.DoUpdate(clsConstantsFuction.ClsFuctionLaborWTS.Update, parameter, true);
        }
        public void DeleteLaborWTS(ClsLaborWTSTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsLaborWTSSP.ID, SqlDbType.Int, b.ID)
                    
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionLaborWTS.Delete, parameter, true);
        }
        public DataTable CheckInputVlaborOPT(string MONo, string OptionID)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo),
                    CreateParameter("@OptionID", SqlDbType.NVarChar, OptionID)
                    
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetCheck;
            return Execute.DoStoreGetByID(sql,parameter, true);
        }
        public DataTable CheckMOQty(string MONo)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo)
                    
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetMOQty;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public DataTable ChekMachineNG(string MONo)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.ChekMachineNG;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public DataTable CheckMOOption(string MONo, string OptionID)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo),
                    CreateParameter("@OptionID", SqlDbType.NVarChar, OptionID)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.CheckMOOption;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        public void UpdateFinishMOOption(ClsMOOptionTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.Finishdate, SqlDbType.DateTime, b.Finishdate),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.MONo, SqlDbType.NVarChar, b.MONo),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsMOOptionSP.Shift, SqlDbType.NVarChar, b.Shift)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.UpdateMOOption;
            Execute.DoStoreGetByID(sql, parameter, true);
        }
        public void TranferLaborToMachine(DateTime fromDate, DateTime toDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date1", SqlDbType.DateTime, fromDate),
                    CreateParameter("@Date2", SqlDbType.DateTime, toDate)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.TranferToMachine;
            Execute.DoStoreGetByID(sql, parameter, true);
        }

        public void TranferMachineToLabor(DateTime fromDate, DateTime toDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date1", SqlDbType.DateTime, fromDate),
                    CreateParameter("@Date2", SqlDbType.DateTime, toDate)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.TranferToLabor;
            Execute.DoStoreGetByID(sql, parameter, true);
        }

        public void UpdateTranferMachineToLabor(DateTime fromDate, DateTime toDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date1", SqlDbType.DateTime, fromDate),
                    CreateParameter("@Date2", SqlDbType.DateTime, toDate)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.UpdateTranferToLabor;
            Execute.DoStoreGetByID(sql, parameter, true);
        }

        public void UpdateTranferLaborToMachine(DateTime fromDate, DateTime toDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date1", SqlDbType.DateTime, fromDate),
                    CreateParameter("@Date2", SqlDbType.DateTime, toDate)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.UpdateTranferToMachine;
            Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllMachineWTStoGA(DateTime FromDate, DateTime ToDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date1", SqlDbType.DateTime, FromDate),
                    CreateParameter("@Date2", SqlDbType.DateTime, ToDate)
                };
            string sql = clsConstantsFuction.ClsFuctionMachineWTS.GetAllWTStoGA;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllWTStoGACheckCode(DateTime FromDate, DateTime ToDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date1", SqlDbType.DateTime, FromDate),
                    CreateParameter("@Date2", SqlDbType.DateTime, ToDate)
                };
            string sql = clsConstantsFuction.ClsFuctionMachineWTS.GetAllWTStoGACheckCode;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        public DataTable GetAllLaborWTStoGA(DateTime FromDate, DateTime ToDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@FromDate", SqlDbType.DateTime, FromDate),
                    CreateParameter("@ToDate", SqlDbType.DateTime, ToDate)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetAllWTStoGA;
            ////string sql1 = clsConstantsFuction.ClsFuctionLaborWTS.PWTSTOGADELETE;
            //string sql2 = clsConstantsFuction.ClsFuctionLaborWTS.PWTSTOGAAPPEND;
            ////Execute.DoStoreGetByID(sql1, parameter, true);
            //Execute.DoStoreGetByID(sql2, parameter, true);
            return Execute.DoStoreGetByID(sql, parameter, true);

        }

        public DataTable GetAllWTSDensan(DateTime FromDate, DateTime ToDate, string order)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@FromDate", SqlDbType.DateTime, FromDate),
                    CreateParameter("@ToDate", SqlDbType.DateTime, ToDate),
                    CreateParameter("@Order", SqlDbType.NVarChar, order),
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.GetAllWTSDensan;
            ////string sql1 = clsConstantsFuction.ClsFuctionLaborWTS.PWTSTOGADELETE;
            //string sql2 = clsConstantsFuction.ClsFuctionLaborWTS.PWTSTOGAAPPEND;
            ////Execute.DoStoreGetByID(sql1, parameter, true);
            //Execute.DoStoreGetByID(sql2, parameter, true);
            return Execute.DoStoreGetByID(sql, parameter, true);

        }
        public void PWTSTOGAAPPEND(DateTime FromDate, DateTime ToDate)
        {
            string sql2 = clsConstantsFuction.ClsFuctionLaborWTS.PWTSTOGAAPPEND;
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@FromDate", SqlDbType.DateTime, FromDate),
                    CreateParameter("@ToDate", SqlDbType.DateTime, ToDate)
                };
            Execute.DoStoreGetByID(sql2, parameter, true);
        }

        //Jig Report
        public DataTable JigReport(DateTime FromDate, DateTime ToDate)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@From", SqlDbType.DateTime, FromDate),
                    CreateParameter("@To", SqlDbType.DateTime, ToDate)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.JigReport;
            return Execute.DoStoreGetByID(sql, parameter, true);

        }
        //chia khoảng trong labor
        public DataTable ChiaKhoangLabor(DateTime From, DateTime To)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@From", SqlDbType.DateTime, From),
                    CreateParameter("@To", SqlDbType.Date, To)
                };
            string sql = clsConstantsFuction.ClsFuctionLaborWTS.ChiaKhoang;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
        //search
        public DataTable SearchMachineWTS(string where)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@where", SqlDbType.NVarChar, where)
                };
            string sql = clsConstantsFuction.ClsFuctionMachineWTS.MachineSearch;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
    }
}
